<template>
  <div class="header">
    <!-- 上面控制抽屉小按钮 -->
    <div class="sliderComponent">
      <label class="switch">
        <input type="checkbox">
        <span class="slider" @click='handleIsShrink'></span>
      </label>
    </div>
    <!-- 面包屑 -->
    <brea-crumb></brea-crumb>
    <!-- 全屏 -->
    <full-screen />
    <!-- 头像 -->
    <div class="avatar">
      <div class="loader">
        <div class="face">
          <div class="circle"></div>
        </div>
        <div class="face">
          <div class="circle"></div>
        </div>
      </div>
      <el-avatar :src="$urlBase + globalAvatarUrl" :size="50"></el-avatar>
      <div class="avatarItem">
        <div class="item" @click="handleBlack">退出登录</div>
        <div class="item" @click="handleGoCenter"> {{globalUsername}}</div>
      </div>
    </div>

  </div>
</template>

<script>
import { mapState } from 'vuex'
import BreaCrumb from './homeHeader/BreaCrumb.vue'
import FullScreen from './homeHeader/FullScreen.vue'
export default {
  components: { BreaCrumb, FullScreen },
  props: ['isShrink'],
  computed: {
    // 全局的username和avatarUrl
    ...mapState(['globalUsername', 'globalAvatarUrl'])
  },
  methods: {
    handleIsShrink () {
      this.$emit('Shrink')
    },
    handleBlack () {
      localStorage.removeItem('token')
      this.$router.push('/login')
    },
    handleGoCenter () {
      this.$router.push({ name: 'center' })
    }
  }
}
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
i {
  color: #000;
  font-size: 20px;
}

.header {
  position: relative;
  display: flex;
  align-items: center;
}
.avatar {
  position: absolute;
  top: 5px;
  width: 50px;
  height: 50px;
  right: 20px;
  cursor: pointer;
  translate: all 0.3s;
  &:hover .avatarItem {
    max-height: 500px;
  }
}
.avatarItem {
  position: absolute;
  top: 50px;
  right: -30px;
  z-index: 999;
  max-height: 0px;
  background: #fff;
  overflow: hidden;
  transition: all 1s;
  .item {
    height: 50px;
    width: 100px;
    text-align: center;
    border-bottom: 1px solid #ddd;
    line-height: 50px;
  }
}
/* From uiverse.io by @Voxybuns */
/* The switch - the box around the slider */
.switch {
  /* Variables */
  --switch_width: 2em;
  --switch_height: 1em;
  --thumb_color: #e8e8e8;
  --track_color: #e8e8e8;
  --track_active_color: #888;
  --outline_color: #000;
  font-size: 17px;
  position: relative;
  display: inline-block;
  width: var(--switch_width);
  height: var(--switch_height);
}

/* Hide default HTML checkbox */
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* The slider */
.slider {
  box-sizing: border-box;
  border: 2px solid var(--outline_color);
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--track_color);
  transition: 0.15s;
  border-radius: var(--switch_height);
}

.slider:before {
  box-sizing: border-box;
  position: absolute;
  content: "";
  height: var(--switch_height);
  width: var(--switch_height);
  border: 2px solid var(--outline_color);
  border-radius: 100%;
  left: -2px;
  bottom: -2px;
  background-color: var(--thumb_color);
  transform: translateY(-0.2em);
  box-shadow: 0 0.2em 0 var(--outline_color);
  transition: 0.15s;
}

input:checked + .slider {
  background-color: var(--track_active_color);
}

input:focus-visible + .slider {
  box-shadow: 0 0 0 2px var(--track_active_color);
}

/* Raise thumb when hovered */
input:hover + .slider:before {
  transform: translateY(-0.3em);
  box-shadow: 0 0.3em 0 var(--outline_color);
}

input:checked + .slider:before {
  transform: translateX(calc(var(--switch_width) - var(--switch_height)))
    translateY(-0.2em);
}

/* Raise thumb when hovered & checked */
input:hover:checked + .slider:before {
  transform: translateX(calc(var(--switch_width) - var(--switch_height)))
    translateY(-0.3em);
  box-shadow: 0 0.3em 0 var(--outline_color);
}
.sliderComponent {
  margin-top: 20px;
}
/* From uiverse.io by @mrhyddenn */
.loader {
  width: 60px;
  height: 60px;
  font-size: 10px;
  position: absolute;
  top: -5px;
  left: -5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loader .face {
  position: absolute;
  border-radius: 50%;
  border-style: solid;
  animation: animate023845 3s linear infinite;
}

.loader .face:nth-child(1) {
  width: 100%;
  height: 100%;
  color: gold;
  border-color: currentColor transparent transparent currentColor;
  border-width: 0.2em 0.2em 0em 0em;
  --deg: -45deg;
  animation-direction: normal;
}

.loader .face:nth-child(2) {
  width: 100%;
  height: 100%;
  color: lime;
  border-color: currentColor currentColor transparent transparent;
  border-width: 0.2em 0em 0em 0.2em;
  --deg: -135deg;
  animation-direction: reverse;
}

.loader .face .circle {
  position: absolute;
  width: 50%;
  height: 0.1em;
  top: 50%;
  left: 50%;
  background-color: transparent;
  transform: rotate(var(--deg));
  transform-origin: left;
}

.loader .face .circle::before {
  position: absolute;
  top: -0.5em;
  right: -0.5em;
  content: "";
  width: 1em;
  height: 1em;
  background-color: currentColor;
  border-radius: 50%;
  box-shadow: 0 0 2em, 0 0 4em, 0 0 6em, 0 0 8em, 0 0 10em,
    0 0 0 0.5em rgba(255, 255, 0, 0.1);
}

@keyframes animate023845 {
  to {
    transform: rotate(1turn);
  }
}
</style>
